from flask import Flask,render_template,send_file,Response
from flask import request
import io

# import requests
import urllib.request as ur
app = Flask(__name__)


@app.route('/vt',methods=["GET"])
def hello_world():  # put application's code here
    lyrs = request.args.get("lyrs")
    x = request.values.get("x")
    y = request.values.get("y")
    z = request.values.get("z")
    hl = request.values.get("hl")
    gl = request.values.get("gl")
    scale = request.values.get("scale")
    url="https://mt0.google.com/vt?lyrs={}&hl={}&gl={}&scale={}&x={}&y={}&z={}".format(lyrs,hl,gl,scale,x,y,z)

    HEADERS = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 Edg/88.0.705.68'}
    header = ur.Request(url, headers=HEADERS)
    err = 0
    while (err < 5):
        try:
            data = ur.urlopen(header).read()
        except:
            err += 1
        else:
            return Response(data, mimetype="image/jpeg")
    return "Bad network link."
@app.route('/', methods=['GET'])
def index():
    # Main page
    return 'Hello'
if __name__ == '__main__':
    app.run(host="0.0.0.0", debug=False, port=5000)
